package com.shanzmoo.admin.web.third;


import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.core.cache.CurrentUserCache;
import com.shanzmoo.db.product.entity.vo.ThirdSkuQueryVO;
import com.shanzmoo.db.third.entity.ThirdProductSkuEntity;
import com.shanzmoo.db.third.service.IThirdProductSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 第三方商品sku 前端控制器
 * </p>
 *
 * @author Xueqz
 * @since 2021-01-09
 */
@RestController
@Api(tags = "第三方平台-第三方信息管理")
@RequestMapping("/third/product/sku")
public class ThirdProductSkuController {

    @Autowired
    private IThirdProductSkuService thirdProductSkuService;

    @ApiOperation(value = "第三方商品信息list")
    @GetMapping("/getThirdProductSkuList")
    public SHttpResponse<PageRespBase<ThirdProductSkuEntity>> attributeList(ThirdSkuQueryVO thirdSkuQueryVO) {
        SResponse<PageRespBase<ThirdProductSkuEntity>> re = thirdProductSkuService.getThirdProductSkuList(thirdSkuQueryVO);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "第三方商品信息list")
    @GetMapping("/delThirdSkuById")
    public SHttpResponse<Boolean> delThirdSkuById(Integer thirdSkuId) {
        ThirdProductSkuEntity thirdProductSkuEntity = new ThirdProductSkuEntity();
        thirdProductSkuEntity.setId(thirdSkuId);
        thirdProductSkuEntity.setDeleted(true);
        thirdProductSkuEntity.setUpdateUser(CurrentUserCache.getUserId());
        thirdProductSkuService.updateById(thirdProductSkuEntity);

        return SHttpResponse.ok(Boolean.TRUE);
    }

    @ApiOperation(value = "添加第三方商品信息")
    @PostMapping("/addThirdProductSku")
    public SHttpResponse<Boolean> addAttribute(@RequestBody ThirdProductSkuEntity thirdProductSkuEntity) {
        thirdProductSkuEntity.setCreateUser(CurrentUserCache.getUserId());
        SResponse<Boolean> re = thirdProductSkuService.addThirdProductSkuEntity(thirdProductSkuEntity);
        return SHttpResponse.transform(re);
    }

}
